package cn.edu.guet.springmvcdemo.util;
/*
 *   @Studio:CHJY · 源梦科技
 *   @Author:lzl
 *   @Ide:IntelliJ IDEA
 *   @Creation time:2021/7/6 20:23
 */

import cn.edu.guet.springmvcdemo.model.User;
import cn.edu.guet.springmvcdemo.mapper.IUserMapper;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.io.InputStream;
import java.util.List;

public class TestUtil {
    private SqlSessionFactory sqlSessionFactory;
    private SqlSession sqlSession;
    @Before
    public void init() throws ClassNotFoundException {
        InputStream in=Class.forName("cn.edu.guet.springmvcdemo.util.TestUtil").getResourceAsStream("/mybatis-config.xml");
        sqlSessionFactory=new SqlSessionFactoryBuilder().build(in);
        sqlSession=sqlSessionFactory.openSession();
    }
    @Test
    public void test(){
        IUserMapper userMapper=sqlSession.getMapper(IUserMapper.class);
        List<User> userList=userMapper.getAllUser();
        System.out.println(userList.size());
    }

    @After
    public void destroy(){
        sqlSession.close();
    }
}
